Skip to content

Document how to format Stan files that use #include - #881

Merged
WardBrian merged 1 commit into
stan-dev:developfrom
soujasK:docs/format-stan-file-includes
Nov 16, 2026
Merged

WardBrian merged 1 commit into
stan-dev:developfrom
soujasK:docs/format-stan-file-includes

Conversation

@soujasK

@soujasK soujasK commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #853

Submission Checklist

  • Run unit tests
  • Declare copyright holder and open-source license: see below

Summary

Documents how to use format_stan_file with Stan programs that use #include:

  • include-paths must be passed in stanc_options, otherwise formatting fails
  • the #include lines are kept, canonicalize="includes" inlines the included files
  • canonicalize has to be passed as the function argument, not inside stanc_options (only include-paths and name keep their value there)

With CmdStan 2.40 two or more includes format fine, so the canonicalize=includes workaround from the issue is not needed anymore (stanc3#1621 is fixed).

Added test_model_format_includes using the existing bernoulli_include.stan. test_compilation.py passes locally with CmdStan 2.40 (11 passed), black/isort/flake8 clean.

AI assistance: I used an AI assistant to help reproduce the issue and draft the change. I reviewed the code and ran the tests myself.

Copyright and Licensing

Copyright holder: Soujas K

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

Signed-off-by: Soujas K <kudchadkarsoujas@gmail.com>

@WardBrian WardBrian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@WardBrian
WardBrian merged commit 6dd393b into stan-dev:develop Nov 16, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

function format_stan_file missing docs, example on how to deal with #includes

2 participants